package pro.cherish.knowledgeumldesignpattern.designPattern.com.cherish.prototype;

import java.util.Date;
//clone 是object的方法，而实现的Coneable是标记接口
public class Sheep implements Cloneable {
    private String name;
    private Date birthday;

    public Sheep(String name) {
        this.name = name;
    }
    public Sheep(String name, Date birthday) {
        this.name = name;
        this.birthday=birthday;
    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Object obj=super.clone();//直接调用object对象的方法
//        添加以下代码深复制（deep clone）
        Sheep s=(Sheep) obj;
        s.birthday=(Date) this.birthday.clone();//把属性也克隆
        return obj;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Sheep{" +
                "name='" + name + '\'' +
                ", birthday=" + birthday +
                '}';
    }
}
